package Week7.J0530;

import java.util.Scanner;

public class 游游的字符串_xv {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        char[] s = scanner.next().toCharArray();

        int ret = (int) 1e9;
        for (char ch = 'a'; ch <= 'z'; ch++) {
            int sum = 0;
            for (int i = 0; i < s.length; i++) {
                sum += Math.min(Math.abs(s[i] - ch), 26 - Math.abs(s[i] - ch));
            }
            ret = Math.min(ret, sum);
        }
        System.out.println(ret);
    }
}
